//
//  HMSportGPSButton.m
//  XRSport
//
//  Created by acer on 16/10/26.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "HMSportGPSButton.h"
#import "HMSportTracking.h"
@implementation HMSportGPSButton

-(void)awakeFromNib
{
    [super awakeFromNib];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeState:) name:HMSportNotificationGPSSignal object:nil];
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)changeState:(NSNotification *)notification
{
    HMSPortGPSSignal state = [notification.object integerValue];
    NSString *imagePrefixStr = _isMapButton ? @"ic_sport_gps_map_" : @"ic_sport_gps_";
    switch (state) {
        case HMSPortGPSSignalDisconnect:
            [self setImage:[UIImage imageNamed:[imagePrefixStr stringByAppendingString:@"disconnect"]] forState:UIControlStateNormal];
            [self setTitle:@"无GPS信号" forState:UIControlStateNormal];
            break;
        case HMSPortGPSSignalBad:
            [self setImage:[UIImage imageNamed:[imagePrefixStr stringByAppendingString:@"connect_1"]] forState:UIControlStateNormal];
            [self setTitle:@"GPS信号差" forState:UIControlStateNormal];
            break;
        case HMSPortGPSSignalNormal:
            [self setImage:[UIImage imageNamed:[imagePrefixStr stringByAppendingString:@"connect_2"]] forState:UIControlStateNormal];
            [self setTitle:@"" forState:UIControlStateNormal];
            break;
        case HMSPortGPSSignalGood:
            [self setImage:[UIImage imageNamed:[imagePrefixStr stringByAppendingString:@"connect_3"]] forState:UIControlStateNormal];
            [self setTitle:@"" forState:UIControlStateNormal];
            break;

    }
    UIEdgeInsets insets = self.contentEdgeInsets;
    insets.right = (state < 2) ? 8 : 4;
    self.contentEdgeInsets = insets;
}
@end
